package com.aaa.cs.controller;

import com.aaa.cs.entity.ViolationRecord;
import com.aaa.cs.service.ViolationRecordService;
import com.aaa.common.constants.ExceptionConstant;
import com.aaa.common.constants.ReturnCode;
import com.aaa.common.util.CustomException;
import com.aaa.common.util.Result;
import com.aaa.cs.entity.ViolationRecord;
import com.aaa.cs.service.ViolationRecordService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
//违章记录

/**
 * (ViolationRecord)表控制层
 *
 * @author makejava
 * @since 2020-11-19 09:33:24
 */
@RestController
@RequestMapping("violationRecord")
public class ViolationRecordController {
    /**
     * 服务对象
     */
    @Resource
    private ViolationRecordService violationRecordService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    public Result selectOne(Integer id) {
        if (null==id){
            throw new CustomException(ExceptionConstant.ID_NOT_NULL.getErrorCode(),
                    ExceptionConstant.ID_NOT_NULL.getErrorMessage());
        }
        return new Result(ReturnCode.SUCCESSS.getCode(),
                ReturnCode.SUCCESSS.getMsg(),this.violationRecordService.queryById(id));
    }

    /**
     *新增
     * @param violationRecord
     * @return
     */
    @PostMapping("insertViolationRecord")
    public Result insertViolationRecord(@RequestBody ViolationRecord violationRecord){
        return new Result(ReturnCode.SUCCESSS.getCode(),
                ReturnCode.SUCCESSS.getMsg(),violationRecordService.insert(violationRecord));
    }

    /**
     * 分页查询
     * @param pageNo
     * @param pageSize
     * @param violationRecord
     * @return
     */
    @GetMapping("queryAll")
    public Result queryAll(Integer pageNo , Integer pageSize, ViolationRecord violationRecord ){
        return violationRecordService.queryPageByParam(pageNo,pageSize,violationRecord);
    }
    /**
     * 修改数据
     * @param violationRecord
     * @return
     */
    @PutMapping("updateViolationRecord")
    public Result updateViolationRecord(@RequestBody ViolationRecord violationRecord){
        return new Result(ReturnCode.SUCCESSS.getCode(),
                ReturnCode.SUCCESSS.getMsg(),violationRecordService.update(violationRecord));
    }

    /**
     * 根据ID删除
     * @param id
     * @return
     */
    @DeleteMapping("deleteViolationRecord")
    public Result deleteViolationRecord(Integer id){
        //当ID为空时抛出自定义异常
        if (null==id){
            throw new CustomException(ExceptionConstant.ID_NOT_NULL.getErrorCode(),
                    ExceptionConstant.ID_NOT_NULL.getErrorMessage());
        }
        return new Result(ReturnCode.SUCCESSS.getCode(),
                ReturnCode.SUCCESSS.getMsg(),violationRecordService.deleteById(id));
    }
//    @GetMapping("insertOrUpdateBatch")
//    public  int insertOrUpdateBatch(ViolationRecord violationRecord){
//        return violationRecordService.insert(violationRecord);
//    }
//    @GetMapping("deleteById")
//    public boolean deleteById(Integer id){
//        return violationRecordService.deleteById(id);
//    }
//    @GetMapping("update")
//    public ViolationRecord update(ViolationRecord violationRecord){
//        return violationRecordService.update(violationRecord);
//    }

//    /**
//     * 通过用户查询
//     * @param id
//     * @return
//     */
//    @GetMapping("queryCarInsuranceByParam")
//    public ViolationRecord queryCarInsuranceByParam(@RequestParam("id") int id){
//        return  this.violationRecordService.queryPageByParam(id);
//    }


}